package com.feng.service.impl;

import com.feng.entity.Test;
import com.feng.service.TestService;
import com.google.gson.Gson;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TestServiceImpl implements TestService {
    @Override
    public String sendPost1() {
        Test test = new Test();
        test.setId(1);
        test.setName("test");
        test.setKey1("key11");
        test.setKey2("key22");
        Gson gson = new Gson();
        String json = gson.toJson(test);
        return json;
    }

    @Override
    public String sendPost2(int totals,int sleeps) throws InterruptedException {

        List<Test> lists = new ArrayList<>();
        for (int i = 1; i <= totals; i++) {
//            Thread.sleep(sleeps*1000);
            Test test = new Test();
            test.setId(i);
            test.setName("test");
            test.setKey1("key11");
            test.setKey2("key22");
//            String json = gson.toJson(test);
//            return json;
            lists.add(test);
        }
        Gson gson = new Gson();
        return gson.toJson(lists);
    }

    @Override
    public String sendPost3(int i) {
        Test test = new Test();
        test.setId(i);
        test.setName("test");
        test.setKey1("key11");
        test.setKey2("key22");
        Gson gson = new Gson();
        String json = gson.toJson(test);
        return json;
    }
}
